<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      console.log(x); //var定义的变量存在变量位置提升,该变量默认值为undefinde 可以拿到变量但不能拿到下面所赋的值
      var x = 123; //这里的x是一个全局变量，任意地方都可以访问
      function fn1(n) {
        //在外部定义的函数也为全局变量，函数的形参为局部变量
        var y = "abc"; //这里的y为局部变量只能在该函数内进行访问
        console.log(x, y);
        console.log(1);
      }
      function fn2() {
        console.log(x + 10);
      }
      fn1(1);
      fn2();
      console.log(x);
      //console.log(y);// y is not defined
    </script>
  </body>
</html>
